package com.ss.android.lockscreen.component;

import android.app.KeyguardManager;
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.IBinder;
import android.support.annotation.Nullable;

import com.ss.android.lockscreen.bb;

public class DaemonService extends Service {
    private BroadcastReceiver a;
    private boolean b;

    public DaemonService() {

        this.b = false;
    }

    private void a() {
        if (this.b) {
            this.unregisterReceiver(this.a);
            this.b = false;
        }
    }

    @Nullable
    public IBinder onBind(Intent arg2) {
        return null;
    }

    public void onDestroy() {
        super.onDestroy();
        if (this != null) {
            if (android.support.design.a.C == null || android.support.design.a.D == null) {
                Object v0 = ((Context) this).getSystemService("keyguard");
                android.support.design.a.C = ((KeyguardManager) v0);
                android.support.design.a.D = ((KeyguardManager) v0).newKeyguardLock(System.currentTimeMillis() + "");
            }

            try {
                android.support.design.a.D.reenableKeyguard();
            } catch (SecurityException v0_1) {
                v0_1.printStackTrace();
            }
        }

        this.a();
    }

    public int onStartCommand(Intent arg5, int arg6, int arg7) {
        Integer v0_2;
        Object v0;
        if (this != null) {
            if (android.support.design.a.C == null || android.support.design.a.D == null) {
                v0 = ((Context) this).getSystemService("keyguard");
                android.support.design.a.C = ((KeyguardManager) v0);
                android.support.design.a.D = ((KeyguardManager) v0).newKeyguardLock(System.currentTimeMillis() + "");
            }

            try {
                android.support.design.a.D.disableKeyguard();
            } catch (SecurityException v0_1) {
                v0_1.printStackTrace();
            }
        }

        bb.a();
        if (bb.c()) {
            this.a();
            if (!this.b) {
                this.a = new e();
                IntentFilter v1 = new IntentFilter();
                Integer priority = (Integer) com.ss.android.lockscreen.aa.a().get(this.getPackageName());
                if (priority == null) {
                    priority = Integer.valueOf(999);
                }

                v1.setPriority(priority.intValue());
                v1.addAction("android.intent.action.SCREEN_ON");
                v1.addAction("android.intent.action.SCREEN_OFF");
                v1.addAction("android.intent.action.USER_PRESENT");
                this.registerReceiver(this.a, v1);
                this.b = true;
            }
        }

        return 2;
    }
}

